const dbConfig = require("../../../utils/dbConfig");

// 获取用户
getUsers = async (req, res) => {
  let sql = "select * from user"
  let sqlArr = []
  try {
    let data = await dbConfig.SySqlConnect(sql, sqlArr)
    res.send({
      code: 200,
      data: data
    })
  } catch (e) {
    res.send({
      code: 500,
      tip: "服务器出错了"
    })
  }
}

// 认证结果
saveCertification = async (req, res) => {
  let { userID, judge } = req.body
  if (judge === 'pass') {
    judge = 'true'
  }
  let sql = 'update user set certified=? where userID=?'
  let sqlArr = [judge, userID]
  let result = await dbConfig.SySqlConnect(sql, sqlArr)
  if (result.affectedRows === 1) {
    res.send({
      'code': 200,
      'msg': '认证成功'
    })
  } else {
    res.send({
      'code': 400,
      'msg': '认证失败'
    })
  }
}

module.exports = {
  getUsers,
  saveCertification
};